<?php
include_once("../config.php");
$uid = $_GET['uid'];
$gcs = $_GET['gcs'];
//$zt = $_GET['zt'];
$yj = $_GET['yj'];
//$id = $_GET['id'];
$status = $_GET['status'];
$t=time();
$uid = str_ireplace($search, '', $uid);
$yj = str_ireplace($search, '', $yj);
$gcs = str_ireplace($search, '', $gcs);
$zt=intval($_GET['zt']);
$id=intval($_GET['id']);

$sql = "select status,xxzx from wenti where id=$id";
$requ = mysqli_query($con,$sql);
$rs = mysqli_fetch_array($requ);
if($rs['status']!=$status){
	die('{"status":"0","msg":"此单已被其他管理员审核"}');
}

$sql = "update wenti set status=$zt,xxzx='$uid',xxzxyj='$yj',wxz='$gcs',pdsj=$t where id=$id";
mysqli_query($con,$sql);
if(mysqli_affected_rows($con)){
	$result = '{"status":"1","msg":"ok"}';
	$ok = true;
}else{
	$result = '{"status":"-1","msg":"操作失败，请重试"}';
	$ok = false;
}
echo $result;

if($ok){
	include_once("jssdk.php");
	$jssdk = new JSSDK($appid, $secretkey);
	$accesstoken=$jssdk->getAccessToken();
	

	$sql = "select lxr,xm,tel,dz,gz from wenti where id=$id";
	$requ = mysqli_query($con,$sql);
	$rs=mysqli_fetch_array($requ);
		$data=array(
			"touser"=>$gcs,
			"page"=>"/pages/gcsjd/gcsjd?mode=xwxd&d=0&id=$id",
			"template_id"=>"Pdoi-osurewAKPVFo7UkfPHMC-wR_k8uvGG3BsmkNcY",
			"miniprogram_state"=>"formal",
			"data"=>array(
				"name1"=>array(
					"value"=>$rs['lxr']
				),
				"phrase2"=>array(
					"value"=>$rs['xm']
				),
				"phone_number3"=>array(
					"value"=>$rs['tel']
				),
				"thing5"=>array(
					"value"=>$rs['dz']
				),
				"thing8"=>array(
					"value"=>$rs['gz']
				)
			)
		);
		$data=json_encode($data);
		$url="https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=$accesstoken";
		$r=https_request($url,$data);
		$myfile = fopen("send.log", "a");
		fwrite($myfile, date("Y-m-d H:i:s",time()));
		fwrite($myfile, "\r\n");
		fwrite($myfile, "新维修派单");
		fwrite($myfile, "\r\n");
		fwrite($myfile,  var_export($data,true));
		fwrite($myfile, "\r\n");
		fwrite($myfile,  var_export($r,true));
		fwrite($myfile, "\r\n\r\n");
		fclose($myfile);

	mysqli_free_result($requ);
	//$u = json_encode($u);
	//$href = $url."mini/dingyuexiaoxi/index.php?mode=wxsp&user=$u";
	//httpGet($href);
}


function httpGet($url) {
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_TIMEOUT, 500);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($curl, CURLOPT_URL, $url);
    $res = curl_exec($curl);
    curl_close($curl);
    return $res;
}

function https_request($url, $data = null){
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
    if (!empty($data)) {
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    }
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $output = curl_exec($curl);
    curl_close($curl);
    return $output;
}















?>